package com.example.controller;

import com.example.common.PageResult;
import com.example.common.Result;
import com.example.pojo.vo.PetQueryVo;
import com.example.pojo.vo.PetRecognitionVo;
import com.example.service.PetRecognizeService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;

/**
 * 宠物识别 controller 层
 */
@RestController
@RequestMapping("/recognize")
public class PetRecognizeController {

    @Resource
    private PetRecognizeService petRecognizeService;

    @PostMapping("/pet")
    public Result petRecognize(@RequestBody MultipartFile image) throws IOException {
        List<PetRecognitionVo> resultList = this.petRecognizeService.petRecognize(image);
        return Result.success(resultList);
    }

    @PostMapping("/search")
    public Result petPageQueryByImage(
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize,
            @RequestPart(required = false) MultipartFile image
    ) throws IOException {
        PageResult<PetQueryVo> pageResult = this.petRecognizeService.petPageQueryByImage(pageNum, pageSize, image);
        return Result.success(pageResult);
    }
}
